﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace TrainingWorkshop.DAL
{
    public class LevelRepository_Sql : IRepository
    {
        private SqlConnection sqlConnection;

        public LevelRepository_Sql(SqlConnection sqlConnection)
        {
            // TODO: Complete member initialization
            this.sqlConnection = sqlConnection;
        }
        public TResualt Select<TResualt, T>(T t)
        {

            TResualt result = default(TResualt);
            List<Model.Level> levelList = new List<Model.Level>();
            
            using (SqlConnection conn = new SqlConnection(SQLHelper.ConnectionStringProjectb))
            {
                conn.Open();
                string selectStatement = "select * from Level";
                SqlDataAdapter da = new SqlDataAdapter(selectStatement, conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                //convert to list
                foreach (DataRow row in dt.Rows)
                {
                    Model.Level level = new Model.Level(Convert.ToInt32(row[0]), row[1].ToString().Trim());
                    levelList.Add(level);
                }
            }
            result = (TResualt)(object)levelList;
            return result;
        }

        public void SelectAll()
        {
            Console.Write("Insert");
        }
 
    }
    
}
